local BaseWnd = require(SCRIPTS_DIR .. ".wnds.BaseWnd");
local LoadingWnd = class("LoadingWnd",BaseWnd);
function LoadingWnd:ctor()
    self.curpencent = 0
    self.scheduler = nil
	LoadingWnd.super.ctor(self);
end

function LoadingWnd:setPrecent()
    self.curpencent = self.curpencent + 1
    self.process:setPercent(self.curpencent);
    self.mjIcon:setPosition(self.initPosX + self.length * self.curpencent / 100,self.initPosY)
    if self.curpencent >= 100 then
        mgrs.scheduler:unscheduleGlobal(self.scheduler)
        mgrs.scheduler:performWithDelayGlobal(function()
            self:close();
        end,0.1);
    end
end

function LoadingWnd:onOpen()
    self.process = self:widget("middle.loadingbar");
    self.mjIcon = self:widget("middle.mj");
    self.initPosX,self.initPosY = self.mjIcon:getPosition()
    self.length = self:widget("middle.barBg"):getContentSize().width
    self.scheduler = mgrs.scheduler:scheduleUpdateGlobal(handler(self,self.setPrecent))
end

function LoadingWnd:onClose()
	--mgrs.animate:removeAnimation("loadingCat");
end



------------------------------------------------------------------基础类调用-----------------------------------------------------------------------------
function LoadingWnd:reqData(handler)
	handler(true);	
end

function LoadingWnd:getLayer()
	return enums.Layer.Loading;
end

function LoadingWnd:getPreloadResList()
	return {};
end

function LoadingWnd:getExclusiveType()
	return 0;
end

function LoadingWnd:isOpenCloseSoundEnabled()
	return false;
end

function LoadingWnd:onEnter()
	mgrs.log:printDebug("LoadingWnd:onEnter");
end
function LoadingWnd:onExit()
	mgrs.log:printDebug("LoadingWnd:onExit");
end
function LoadingWnd:onEnterTransitionFinish()
	mgrs.log:printDebug("LoadingWnd:onEnterTransitionFinish");
end

function LoadingWnd:onExitTransitionStart()
	mgrs.log:printDebug("LoadingWnd:onExitTransitionStart");
end


function LoadingWnd:onClose()
    
end


mgrs.wnd:registerWnd(enums.Wnd.Loading,LoadingWnd);

